"""
    @Author  ：思念 
    @File    ：10.哨兵模式.py
    @Date    ：2025/3/4 9:56 
"""

import threading
import time
from queue import Queue

def worker_1(q):
    for i in range(1,6):
        q.put(i)
        print("生产者：", i)



def worker_2(q):
    while True:
        i = q.get()
        if i is not None:
            print("消费者：", i)
            time.sleep(2)
        else:
            break


if __name__ == '__main__':
    queue = Queue()
    t1 = threading.Thread(target=worker_1,args=(queue,))
    t2 = threading.Thread(target=worker_2,args=(queue,))
    t1.start()
    t2.start()
    t1.join()
    queue.put(None)
    t2.join()
    print("主程序结束。。。。。。")
